package com.ruoyi.stock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.stock.domain.StockTradeDate;
import com.ruoyi.stock.service.IStockTradeDateService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 股票交易日历信息Controller
 *
 * @author ruoyi
 * @date 2021-11-02
 */
@RestController
@RequestMapping("/stock/date")
public class StockTradeDateController extends BaseController {
  @Autowired private IStockTradeDateService stockTradeDateService;

  /** 查询股票交易日历信息列表 */
  @PreAuthorize("@ss.hasPermi('stock:date:list')")
  @GetMapping("/list")
  public TableDataInfo list(StockTradeDate stockTradeDate) {
    startPage();
    List<StockTradeDate> list = stockTradeDateService.selectStockTradeDateList(stockTradeDate);
    return getDataTable(list);
  }

  /** 导出股票交易日历信息列表 */
  @PreAuthorize("@ss.hasPermi('stock:date:export')")
  @Log(title = "股票交易日历信息", businessType = BusinessType.EXPORT)
  @GetMapping("/export")
  public AjaxResult export(StockTradeDate stockTradeDate) {
    List<StockTradeDate> list = stockTradeDateService.selectStockTradeDateList(stockTradeDate);
    ExcelUtil<StockTradeDate> util = new ExcelUtil<StockTradeDate>(StockTradeDate.class);
    return util.exportExcel(list, "股票交易日历信息数据");
  }

  /** 获取股票交易日历信息详细信息 */
  @PreAuthorize("@ss.hasPermi('stock:date:query')")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") Long id) {
    return AjaxResult.success(stockTradeDateService.selectStockTradeDateById(id));
  }

  /** 新增股票交易日历信息 */
  @PreAuthorize("@ss.hasPermi('stock:date:add')")
  @Log(title = "股票交易日历信息", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@RequestBody StockTradeDate stockTradeDate) {
    return toAjax(stockTradeDateService.insertStockTradeDate(stockTradeDate));
  }

  /** 修改股票交易日历信息 */
  @PreAuthorize("@ss.hasPermi('stock:date:edit')")
  @Log(title = "股票交易日历信息", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@RequestBody StockTradeDate stockTradeDate) {
    return toAjax(stockTradeDateService.updateStockTradeDate(stockTradeDate));
  }

  /** 删除股票交易日历信息 */
  @PreAuthorize("@ss.hasPermi('stock:date:remove')")
  @Log(title = "股票交易日历信息", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public AjaxResult remove(@PathVariable Long[] ids) {
    return toAjax(stockTradeDateService.deleteStockTradeDateByIds(ids));
  }
}
